<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>02_回调形式的ref</title>
</head>

<body>
    <div id="app"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>

    <script type="text/babel">
        class MyComponent extends React.Component{
            showData1 = ()=>{
                // 如果ref采用回调的形式时，则组件实例的 refs 中就没有数据
                // ref 中的回调过来所携带的参数刚好是被标记元素的真实DOM
                console.log(this);
                const {input1} = this
                alert(input1.value)
            }
            showData2 = ()=>{
                const {input2} = this
                alert(input2.value)
            }
            render(){
                return (
                    <div>
                        <input ref={cnode=> this.input1=cnode} placeholder="点击按钮弹出信息"/>
                        <button onClick={this.showData1}>显示左侧信息</button>
                        <input onBlur={this.showData2} ref={cnode=> this.input2=cnode} placeholder="离焦点触发"/>
                    </div>
                )
            }
        }
        ReactDOM.render(<MyComponent/>,document.getElementById("app"))
    </script>
</body>

</html>